package main

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/broker"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-micro/util/log"
	"github.com/micro/go-plugins/broker/rabbitmq"
	"github.com/micro/go-plugins/registry/consul"
	"go-micro-service/handler"
	user_medreams_com "go-micro-service/interface"
)

func main() {
	//rabbitmq链接
	newBroker := rabbitmq.NewBroker(
		broker.Addrs("amqp://admin:admin@106.12.7.53:5672"),
	)

	newBroker.Init()
	newBroker.Connect()

	newRegistry := consul.NewRegistry(registry.Addrs("106.12.7.53:8500"))
	// New Service
	service := micro.NewService(
		micro.Name("go.micro.srv.go"),
		micro.Version("latest"),
		micro.Registry(newRegistry),
		micro.Broker(newBroker),
	)
	// Initialise service
	service.Init()

	//创建消息发布者
	publisher := micro.NewPublisher("go.micro.srv.micro_service_rabbit", service.Client())

	// Register Handler
	user_medreams_com.RegisterUserServiceHandler(service.Server(), &handler.UserHandler{Publisher: publisher})

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
